package com.googlemap1;

import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends MapActivity{
	MapView map;
	MapController control;
	Drawable d;
	List<Overlay> overlayList;
	LocationManager locationmana;
	String towers;
	int kinhdo;
	int vido;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        map = (MapView)findViewById(R.id.Mapview);
        map.setBuiltInZoomControls(true);
        control = map.getController();
        
        overlayList = map.getOverlays();
        
        d= getResources().getDrawable(R.drawable.icon_man);
        
        locationmana = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        Criteria crit = new Criteria();
        towers = locationmana.getBestProvider(crit, false);
        
        LocationListener lis = new LocationListener() 
        {
			
			public void onStatusChanged(String provider, int status, Bundle extras) {
				// TODO Auto-generated method stub
				
			}
			
			public void onProviderEnabled(String provider) {
				// TODO Auto-generated method stub
				
			}
			
			public void onProviderDisabled(String provider) {
				// TODO Auto-generated method stub
				
			}
			
			public void onLocationChanged(Location location) {
				vido = (int)(location.getLatitude()*1E6);
	            kinhdo  = (int)(location.getLongitude()*1E6);
	            GeoPoint toado = new GeoPoint(vido, kinhdo);
	            //control.setCenter(toado);
	            OverlayItem overlayItem = new OverlayItem(toado, "ko bik", "ko bikk lun");
	            CustomPinpoint custom = new CustomPinpoint(d,MainActivity.this);
	            custom.insertPinpoint(overlayItem);
	            overlayList.add(custom);
				// TODO Auto-generated method stub
				
			}
		};
		locationmana.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, lis);
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}

}